package com.asia5b.a5mall.goods.adapter

import androidx.core.content.ContextCompat
import android.text.TextUtils
import android.view.View
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.TextView
import com.asia5b.a5mall.goods.R
import com.asia5b.a5mall.goods.dialog.GoodsSpecHelper
import com.asia5b.a5mall.goods.widget.SearchGoodsHelper
import com.asia5b.a5mall.middleware.model.goods.SelectorKeyBean
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder

/**
 * Created by zhangyuncai on 2020/5/13.
 */
class GoodsCompKeyAdapter(list: ArrayList<SelectorKeyBean>, var params: HashMap<String, Any>) :
        BaseQuickAdapter<SelectorKeyBean, BaseViewHolder>(R.layout.item_goodscomp_key_adapter, list) {
    var selectPosition = -1
    override fun convert(helper: BaseViewHolder, item: SelectorKeyBean) {
        helper.setText(R.id.tv_goodscomp_key, item.key)

        val iv_goodscomp_key_arrow = helper.getView<ImageView>(R.id.iv_goodscomp_key_arrow)
        val tv_goodscomp_key = helper.getView<TextView>(R.id.tv_goodscomp_key)
        val ll_goodscomp_key = helper.getView<LinearLayout>(R.id.ll_goodscomp_key)

        tv_goodscomp_key.setTextColor(ContextCompat.getColor(context, R.color.common_text_black))
        val position = helper.layoutPosition
        iv_goodscomp_key_arrow.visibility = View.VISIBLE
        iv_goodscomp_key_arrow.isSelected = (selectPosition == position)
        tv_goodscomp_key.isSelected = (selectPosition == position)
        ll_goodscomp_key.isSelected = (selectPosition == position)

        val selectValue = SearchGoodsHelper.getSelectValue(item, params)
        if (!TextUtils.isEmpty(selectValue)) {
            ll_goodscomp_key.isSelected = true
            iv_goodscomp_key_arrow.visibility = View.GONE
            tv_goodscomp_key.setText(selectValue)
            tv_goodscomp_key.setTextColor(ContextCompat.getColor(context, R.color.common_text_blue))
        }


    }

    override fun getItemCount(): Int {
        if (data.size > 4) {
            return 4
        }
        return super.getItemCount()
    }
}